#include <iostream>
#include <vector>
#include <list>
#include <string>
#include <algorithm>
#include <set>

using std::vector;
using std::list;
using std::string;
using std::ostream;
using std::cout; 
using std::endl;
using std::set;


class Student
{
    friend ostream& operator<<(ostream& os, const Student& rhs);
public:
    Student(string name, int age, double chinese, double math, double english);
    double sum() const;

private:
    string _name;
    int _age;
    double _chinese;
    double _math;
    double _english;
};
Student::Student(string name, int age, double chinese, double math, double english)
    : _name(name)
    , _age(age)
    , _chinese(chinese)
    , _math(math)
    , _english(english){

}

double Student::sum() const{
    return _chinese + _math + _english;
}

ostream& operator<<(ostream& os, const Student& rhs){
    os << rhs._name << " ";
    os << rhs._age << " ";
    os << rhs._chinese << " ";
    os << rhs._math << " ";
    os << rhs._english;
    return os;
}

// 题目：学生成绩管理系统
// 题目要求：
// 1 .制作一个学生成绩单管理系统
// 2 .将student自定义数据类型进行排序，student中属性有姓名、年龄、语文成绩，数学成绩，英语成绩
// 排序规则：按照总成绩sum进行降序，如果总成绩sum相同按照语文成绩进行降序
// 提示：熟悉list容器的基本操作：包括初始化、遍历、排序等等
bool cmp(const Student &a, const Student &b){
    return a.sum() > b.sum();
}
int main()
{
    list<Student> stus;
    stus.emplace_back("斛珠", 18, 99.9, 99.9, 99.9);
    stus.emplace_back("张三", 19, 88.8, 65.6, 97.5);
    stus.emplace_back("李四", 20, 78.8, 75.6, 47.5);
    stus.emplace_back("王五", 19, 98.8, 55.6, 77.5);
    stus.emplace_back("赵六", 20, 38.8, 77.6, 41.5);

    stus.sort(cmp);

    cout << "姓名" << " " << "年龄" << " " << "语文" << " " << "数学" << " " << "英语" << endl;
    for(auto& elem : stus){
        cout << elem << " " << elem.sum() << endl;
    }
    
    return 0;
}